package com.rrd.mex.dw.mr.babel.parser;

import com.alibaba.fastjson.JSONObject;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.tanzhi.OverdueReportRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;

/**
 * @Classname OverdueReportRecordParse
 * @Description 探知-逾期分析报告
 * @Date 2023/8/9 18:24
 * @Created by zxb
 */

public class OverdueReportRecordParse extends ParseBase {
    Text key = new Text();
    Text value = new Text();

    @Override
    public boolean parseJob(Mapper.Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        OverdueReportRecord obj = (OverdueReportRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful,1);

        sb.append(obj.getCode() == null ? "" : obj.getCode()).append(CRT001);
        sb.append(obj.getMsg() == null ? "" : obj.getMsg()).append(CRT001);
        sb.append(obj.getToken() == null ? "" : obj.getToken()).append(CRT001);

        JSONObject data = obj.getData() == null ? new JSONObject() : obj.getData();
        sb.append(formatValue(data.getString("tzbg_loovev_w1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovev_w2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovev_w3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovev_m1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovev_m2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovev_m3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovev_m6"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovreesu_w1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovreesu_w2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovreesu_w3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovreesu_m1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovreesu_m2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovreesu_m3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovreesu_m6"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovrepl_w1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovrepl_w2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovrepl_w3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovrepl_m1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovrepl_m2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovrepl_m3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovrepl_m6"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_lorerepl_w1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_lorerepl_w2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_lorerepl_w3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_lorerepl_m1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_lorerepl_m2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_lorerepl_m3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_lorerepl_m6"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovamma_w1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovamma_w2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovamma_w3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovamma_m1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovamma_m2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovamma_m3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovamma_m6"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovdam_w1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovdam_w2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovdam_w3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovdam_m1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovdam_m2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovdam_m3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovdam_m6"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovredam_w1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovredam_w2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovredam_w3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovredam_m1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovredam_m2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovredam_m3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovredam_m6"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovevpps_w1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovevpps_w2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovevpps_w3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovevpps_m1"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovevpps_m2"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovevpps_m3"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovevpps_m6"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovdlv_m24"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovrlt_m24"))).append(CRT001);
        sb.append(formatValue(data.getString("tzbg_loovlati_m24"))).append(CRT001);

        key.set(getKey());
        value.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, value);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_tanzhi_overdue_report_inc";
    }

    @Override
    public String getType() {
        return RecordType.OVERDUE_REPORT_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "探知-逾期分析报告";
    }

    @Override
    public BaseModel getModel() {
        return new OverdueReportRecord();
    }
}
